/*     */ package com.zimbra.qa.unittest.prov.soap;
/*     */ 
/*     */ import com.zimbra.common.localconfig.KnownKey;
/*     */ import com.zimbra.common.localconfig.LC;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.soap.Element;
/*     */ import com.zimbra.common.soap.SoapHttpTransport;
/*     */ import com.zimbra.common.soap.SoapHttpTransport.HttpDebugListener;
/*     */ import com.zimbra.common.soap.SoapProtocol;
/*     */ import com.zimbra.common.soap.SoapTransport;
/*     */ import com.zimbra.common.util.CliUtil;
/*     */ import com.zimbra.cs.account.accesscontrol.RightManager;
/*     */ import com.zimbra.qa.unittest.TestUtil;
/*     */ import com.zimbra.qa.unittest.prov.LocalconfigTestUtil;
/*     */ import com.zimbra.qa.unittest.prov.ProvTest;
/*     */ import com.zimbra.soap.JaxbUtil;
/*     */ import com.zimbra.soap.admin.message.ReloadLocalConfigRequest;
/*     */ import com.zimbra.soap.admin.message.ReloadLocalConfigResponse;
/*     */ import com.zimbra.soap.type.AccountBy;
/*     */ import com.zimbra.soap.type.AccountSelector;
/*     */ import java.io.IOException;
/*     */ import org.junit.BeforeClass;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class SoapTest
/*     */   extends ProvTest
/*     */ {
/*  44 */   private static boolean JSON = false;
/*     */   
/*     */   private static final String SOAP_TEST_BASE_DOMAIN = "soaptest";
/*     */   
/*  48 */   private static String PASSWORD = "test123";
/*     */   private static SoapHttpTransport.HttpDebugListener soapDebugListener;
/*     */   
/*     */   @BeforeClass
/*     */   public static void beforeClass() throws Exception {
/*  53 */     CliUtil.toolSetup();
/*  54 */     soapDebugListener = new SoapDebugListener();
/*     */     
/*     */ 
/*  57 */     RightManager.getInstance();
/*     */   }
/*     */   
/*     */   public static String baseDomainName() {
/*  61 */     StackTraceElement[] s = new RuntimeException().getStackTrace();
/*  62 */     return s[1].getClassName().toLowerCase() + "." + "soaptest" + "." + "unittest";
/*     */   }
/*     */   
/*     */   static SoapTransport authUser(String acctName) throws Exception
/*     */   {
/*  67 */     return authUser(acctName, PASSWORD);
/*     */   }
/*     */   
/*     */   static SoapTransport authUser(String acctName, String password) throws Exception {
/*  71 */     AccountSelector acct = new AccountSelector(AccountBy.name, acctName);
/*     */     
/*     */ 
/*  74 */     SoapHttpTransport transport = new SoapHttpTransport(TestUtil.getSoapUrl());
/*  75 */     transport.setHttpDebugListener(soapDebugListener);
/*     */     
/*  77 */     com.zimbra.soap.account.message.AuthRequest req = new com.zimbra.soap.account.message.AuthRequest(acct, password);
/*  78 */     com.zimbra.soap.account.message.AuthResponse resp = (com.zimbra.soap.account.message.AuthResponse)invokeJaxb(transport, req);
/*  79 */     transport.setAuthToken(resp.getAuthToken());
/*  80 */     return transport;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public static SoapTransport authUser(String acctName, boolean csrfEnabled)
/*     */     throws ServiceException, IOException
/*     */   {
/*  91 */     AccountSelector acct = new AccountSelector(AccountBy.name, acctName);
/*     */     
/*     */ 
/*  94 */     SoapHttpTransport transport = new SoapHttpTransport("http://localhost:7070/service/soap/");
/*  95 */     transport.setHttpDebugListener(soapDebugListener);
/*     */     
/*  97 */     com.zimbra.soap.account.message.AuthRequest req = new com.zimbra.soap.account.message.AuthRequest(acct, PASSWORD);
/*  98 */     req.setCsrfSupported(Boolean.valueOf(csrfEnabled));
/*  99 */     com.zimbra.soap.account.message.AuthResponse resp = (com.zimbra.soap.account.message.AuthResponse)invokeJaxb(transport, req);
/* 100 */     transport.setAuthToken(resp.getAuthToken());
/* 101 */     return transport;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public static SoapTransport authUser(String acctName, boolean csrfEnabled, boolean setCsrfToken)
/*     */     throws ServiceException, IOException
/*     */   {
/* 112 */     AccountSelector acct = new AccountSelector(AccountBy.name, acctName);
/*     */     
/*     */ 
/* 115 */     SoapHttpTransport transport = new SoapHttpTransport("http://localhost:7070/service/soap/");
/* 116 */     transport.setHttpDebugListener(soapDebugListener);
/*     */     
/* 118 */     com.zimbra.soap.account.message.AuthRequest req = new com.zimbra.soap.account.message.AuthRequest(acct, PASSWORD);
/* 119 */     req.setCsrfSupported(Boolean.valueOf(csrfEnabled));
/* 120 */     com.zimbra.soap.account.message.AuthResponse resp = (com.zimbra.soap.account.message.AuthResponse)invokeJaxb(transport, req);
/* 121 */     transport.setAuthToken(resp.getAuthToken());
/* 122 */     if (setCsrfToken) {
/* 123 */       transport.setCsrfToken(resp.getCsrfToken());
/*     */     }
/* 125 */     return transport;
/*     */   }
/*     */   
/*     */   public static SoapTransport authAdmin(String acctName) throws Exception {
/* 129 */     return authAdmin(acctName, PASSWORD);
/*     */   }
/*     */   
/*     */   public static SoapTransport authAdmin(String acctName, String password) throws Exception {
/* 133 */     SoapHttpTransport transport = new SoapHttpTransport(TestUtil.getAdminSoapUrl());
/* 134 */     transport.setHttpDebugListener(soapDebugListener);
/*     */     
/* 136 */     com.zimbra.soap.admin.message.AuthRequest req = new com.zimbra.soap.admin.message.AuthRequest(acctName, password);
/* 137 */     com.zimbra.soap.admin.message.AuthResponse resp = (com.zimbra.soap.admin.message.AuthResponse)invokeJaxb(transport, req);
/* 138 */     transport.setAuthToken(resp.getAuthToken());
/* 139 */     return transport;
/*     */   }
/*     */   
/*     */   static SoapTransport authZimbraAdmin() throws Exception {
/* 143 */     return authAdmin(LC.zimbra_ldap_user.value(), LC.zimbra_ldap_password.value());
/*     */   }
/*     */   
/*     */   static void modifyLocalconfigAndReload(SoapTransport transport, KnownKey key, String value) throws Exception
/*     */   {
/* 148 */     LocalconfigTestUtil.modifyLocalConfig(key, value);
/*     */     
/*     */ 
/* 151 */     ReloadLocalConfigRequest req = new ReloadLocalConfigRequest();
/* 152 */     ReloadLocalConfigResponse resp = (ReloadLocalConfigResponse)invokeJaxb(transport, req);
/*     */   }
/*     */   
/*     */   public static <T> T invokeJaxb(SoapTransport transport, Object jaxbObject) throws ServiceException, IOException
/*     */   {
/* 157 */     return (T)invokeJaxb(transport, jaxbObject, JSON ? SoapProtocol.SoapJS : SoapProtocol.Soap12);
/*     */   }
/*     */   
/*     */   public static <T> T invokeJaxb(SoapTransport transport, Object jaxbObject, SoapProtocol proto)
/*     */     throws ServiceException, IOException
/*     */   {
/* 163 */     Element req = JaxbUtil.jaxbToElement(jaxbObject, proto.getFactory());
/*     */     
/* 165 */     Element res = transport.invoke(req);
/* 166 */     return (T)JaxbUtil.elementToJaxb(res);
/*     */   }
/*     */   
/*     */   public static <T> T invokeJaxbOnTargetAccount(SoapTransport transport, Object jaxbObject, String targetAcctId)
/*     */     throws Exception
/*     */   {
/* 172 */     String oldTarget = transport.getTargetAcctId();
/*     */     try {
/* 174 */       transport.setTargetAcctId(targetAcctId);
/* 175 */       return (T)invokeJaxb(transport, jaxbObject);
/*     */     } finally {
/* 177 */       transport.setTargetAcctId(oldTarget);
/*     */     }
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/qa/unittest/prov/soap/SoapTest.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */